using System;
using System.Collections.Generic;
using Prime31;
using UnityEngine;

internal sealed class NotificationController : MonoBehaviour
{
	public static bool isGetEveryDayMoney;

	public bool pauserTemp;

	private static bool _paused;

	private readonly IList<int> _notificationIds = new List<int>();

	internal static bool Paused
	{
		get
		{
			return _paused;
		}
	}

	private void Start()
	{
		Save.SaveBool("ForceReconnect", false);
		if (!Load.LoadBool("bilZapuskKey"))
		{
			Save.SaveBool("bilZapuskKey", true);
		}
		else
		{
			appStart();
		}
	}

	private void Update()
	{
		if (pauserTemp)
		{
			pauserTemp = false;
			_paused = true;
			PhotonNetwork.Disconnect();
		}
	}

	internal static void ResetPaused()
	{
		_paused = false;
	}

	private void appStop()
	{
		Save.SaveString("appStopTime", DateTime.Now.ToString());
		if (!settings.offlineMode && Application.platform == RuntimePlatform.Android && PhotonNetwork.connected)
		{
			Save.SaveBool("ForceReconnect", true);
			PhotonNetwork.Disconnect();
		}
		int hour = DateTime.Now.Hour;
		int num = 0;
		int num2 = hour + 12;
		if (num2 > 23)
		{
			num2 -= 24;
		}
		if (num2 >= 22)
		{
			num = 36000 + (23 - DateTime.Now.Hour) * 3600 + (60 - DateTime.Now.Minute) * 60;
		}
		if (num2 <= 10)
		{
			num = (10 - DateTime.Now.Hour) * 3600 + (60 - DateTime.Now.Minute) * 60;
		}
		for (int i = 1; i < 7; i++)
		{
			int num3 = num + i * 172800 - 3600;
			string empty = string.Empty;
			int item = EtceteraAndroid.scheduleNotification(num3, "Challenge", "Block City needs a hero! Join the battle!", "Are you ready?", empty);
			_notificationIds.Add(item);
			if (BCWDebug.isDebugBuild)
			{
				break;
			}
		}
	}

	private void appStart()
	{
		if (controllerConnectGame.thisScript != null)
		{
			controllerConnectGame.thisScript.ConnectAfterForceDisconnect();
		}
		Save.SaveBool("ForceReconnect", false);
		foreach (int notificationId in _notificationIds)
		{
			EtceteraAndroid.cancelNotification(notificationId);
		}
		Save.SaveString("appStopTime", string.Empty);
	}

	private void OnApplicationPause(bool pauseStatus)
	{
		if (pauseStatus)
		{
			appStop();
		}
		else
		{
			appStart();
		}
	}
}
